package com.zy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zy.lcpassenger.R;
import com.zy.qudadid.model.GuDingLuChengDetail;

import java.util.ArrayList;

/**
 * Created by liuchao on 2016/12/28.
 */

public class RouteAdapter extends BaseAdapter {

    private Context mContext;
    ArrayList<GuDingLuChengDetail> list;

    public RouteAdapter(Context mContext, ArrayList<GuDingLuChengDetail> list) {
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if(convertView!=null){
            view = convertView;
        }else{
            view = LayoutInflater.from(mContext).inflate(R.layout.route_adapter_item,parent,false);
        }

        ViewHolder holder = (ViewHolder) view.getTag();

        if(holder == null){
            holder = new ViewHolder();

            holder.txtStart = (TextView) view.findViewById(R.id.txtStart);
            holder.txtEnd = (TextView) view.findViewById(R.id.txtEnd);
            holder.txtDay = (TextView) view.findViewById(R.id.txtDay);
            holder.txtNight = (TextView) view.findViewById(R.id.txtNight);


            view.setTag(holder);
        }

        GuDingLuChengDetail item = list.get(position);

        holder.txtStart.setText(item.start_area);
        holder.txtEnd.setText(item.end_area);
        holder.txtDay.setText(item.day+"元");
        holder.txtNight.setText(item.night+"元");


        return view;
    }

    class ViewHolder{
        TextView txtStart,txtEnd,txtDay,txtNight;
    }
}
